/**
 * Author: Dmitry Ustimov
 * Date: 5/11/13
 * Time: 10:03 PM
 */

package com.gmail.dmitryustimov.ms.java7.composite.mod.example;

import java.util.ArrayList;
import java.util.List;

public class Demo {

    public static void main(String[] args) {

        Component<Leaf> leaf1 = new Leaf("Leaf1");
        Component<Leaf> leaf2 = new Leaf("Leaf2");
        Component<Leaf> leaf3 = new Leaf("Leaf3");
        Component<Leaf> leaf4 = new Leaf("Leaf4");

        List<Component<Leaf>> someComponents = new ArrayList<>();
        someComponents.add(leaf1);

        Composite<Leaf> aComposite = new Composite<>("Composite1");
        aComposite.add(leaf2);
        aComposite.add(leaf3);

        someComponents.add(aComposite);

        for (Component<Leaf> c: someComponents) {
            c.doAction();
            if (c.isComposite() == true) {
                c.add(leaf4);
            }
        }

        aComposite.remove(leaf2);

        for (Component<Leaf> c: someComponents) {
            c.doAction();
        }
    }
}
